package com.aliang.shopping.model.converter;


import com.aliang.shopping.model.dto.business.BusinessInsertDTO;
import com.aliang.shopping.model.dto.business.BusinessUpdateDTO;
import com.aliang.shopping.model.dto.common.UpdatePasswordDTO;
import com.aliang.shopping.model.dto.common.UpdateStatusDTO;
import com.aliang.shopping.model.po.Business;
import com.aliang.shopping.model.vo.CommonUserInfoVO;
import com.aliang.shopping.model.vo.business.BusinessExportVO;
import com.aliang.shopping.model.vo.business.BusinessVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

import java.util.List;

/**
 * 商家数据转换器
 */
@Mapper(componentModel = "Spring")
public interface BusinessConverter {

    /**
     * 将商家插入数据传输对象转换为商家实体
     *
     * @param insertDTO
     * @return
     */
    Business toPoByInsertDTO(BusinessInsertDTO insertDTO);

    /**
     * 将商家更新数据传输对象转换为商家实体
     *
     * @param updateDTO
     * @return
     */
    @Mapping(target = "storeName", source = "nickname")
    Business toPoByUpdateDTO(BusinessUpdateDTO updateDTO);

    /**
     * 将商家更新状态数据传输对象转换为商家实体
     *
     * @param updateDTO
     * @return
     */
    Business toPoByUpdateStaticDTO(UpdateStatusDTO updateDTO);

    @Mappings({
            @Mapping(target = "businessStatus", source = "status"),
            @Mapping(target = "status", ignore = true)
    })
    Business toPoByUpdateBusinessStaticDTO(UpdateStatusDTO updateDTO);

    /**
     * 将商家更新密码数据传输对象转换为商家实体
     *
     * @param updateDTO
     * @return
     */
    @Mapping(target = "password", expression = "java(com.aliang.shopping.util.PasswordUtil.encrypt(updateDTO.getNewPassword()))")
    Business toPoByUpdatePasswordDTO(UpdatePasswordDTO updateDTO);

    /**
     * 将商家展示对象转换为商家导出对象
     *
     * @param vo
     * @return
     */

    @Mappings({
            @Mapping(target = "status", expression = "java(CommonConverter.getMsg(vo.getStatus(),\"正常\",\"禁用\"))"),
            @Mapping(target = "businessStatus", expression = "java(CommonConverter.getBusinessStatusMsg(vo.getBusinessStatus()))")
    })
    BusinessExportVO toExportVO(BusinessVO vo);

    List<BusinessExportVO> toImportDTOList(List<BusinessVO> list);

    @Mapping(target = "nickname", source = "storeName")
    CommonUserInfoVO toUserInfoVO(Business business);

    BusinessVO toVO(Business business);
}
